package com.Xsoft.ShoppingList;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View.MeasureSpec;
import android.widget.TextView;

public class ProductListItemView extends TextView {

  private Paint marginPaint;
  private Paint linePaint;
  private int paperColor;
  private float margin;
  private Resources myResources;
	
  public ProductListItemView (Context context, AttributeSet ats, int ds) {
    super(context, ats, ds);
    init();
  }

  public ProductListItemView (Context context) {
    super(context);
    init();
  }

  public ProductListItemView (Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  private void init() {
    // Get a reference to our resource table.
    myResources = getResources();

    // Create the paint brushes we will use in the onDraw method.
    marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    marginPaint.setColor(myResources.getColor(R.color.notepad_margin));
    linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    linePaint.setColor(myResources.getColor(R.color.notepad_lines));

    // Get the paper background color and the margin width.
    paperColor = myResources.getColor(R.color.notepad_paper);
    margin = myResources.getDimension(R.dimen.notepad_margin);
  }

//  @Override
//  public void onDraw(Canvas canvas) {
//    // Color as paper
//    canvas.drawColor(paperColor);
//
//    // Draw ruled lines
//    canvas.drawLine(0, 0, getMeasuredHeight(), 0, linePaint);
//    canvas.drawLine(0, getMeasuredHeight(), 
//                       getMeasuredWidth(), getMeasuredHeight(), 
//                       linePaint);
//
//    // Draw margin
//    canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint);
//
//    // Move the text across from the margin
//    canvas.save();
//    canvas.translate(margin, 0);
//
//    // Use the TextView to render the text.
//    super.onDraw(canvas);
//    canvas.restore();
//  }
//  @Override
//  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
//    // Set the measured dimensions by figuring out the shortest boundary,
//    // height or width.
//    int measuredWidth = measure(widthMeasureSpec);
//    int measuredHeight = measure(heightMeasureSpec);
//
//    int d = Math.min(measuredWidth, measuredHeight);
//
//    setMeasuredDimension(measuredWidth,measuredHeight);
//  }
//
//  private int measure(int measureSpec) {
//    int result = 0; 
//
//    // Decode the measurement specifications.
//    int specMode = MeasureSpec.getMode(measureSpec);
//    int specSize = MeasureSpec.getSize(measureSpec); 
//
//    if (specMode == MeasureSpec.UNSPECIFIED) {
//      // Return a default size of 200 if no bounds are specified. 
//      result = myResources.getDimensionPixelSize(R.dimen.text_view_size)*2;
//    } 
//    else 
//    {
//      // As you want to fill the available space
//      // always return the full available bounds.
//      result = MeasureSpec.EXACTLY;
//    } 
//    return result;
//  }
}